// pages/service/index.js
var util = require("../../utils/util.js");
Page({
  data: {
    phone: "",
    message: ""
  },
  onLoad: function () {
  },
  inputPhone: function (e) {
    this.setData({
      phone: e.detail.value
    });
  },
  inputMeg: function (e) {
    this.setData({
      message: e.detail.value
    });
  },
  doFeedback: function () {
      var phone = this.data.phone
      var msg = this.data.message
      if (!phone) {
        return wx.showToast({
          title: '请输入您的联系电话！',
          icon: 'none'
        })
      }
    if (!msg) {
      return wx.showToast({
        title: '请输入您的建议！',
        icon: 'none'
      })
    }
    util.djax({
      url: '/wxapp/other/advise/',
      data: {
        a: phone,
        b: msg
      }
    }).then(function(res) {
      if (res.code==5002) {
        return wx.showToast({
          title: '提交过于频繁，请稍后再试！',
          icon: 'none'
        })
      }
      if (res.code!=1001) {
        return wx.showToast({
          title: res.msg,
          icon: 'none'
        })
      } else {
        wx.showToast({
          title: '感谢您的宝贝建议！',
        })
        wx.redirectTo({
          url: '/pages/user/index',
        })
      }
    })

  }
})